/****** Object:  Stored Procedure [dbo].[v_DoanhThuSanPham] Script Date: 6/12/2012 ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].v_KhachHangMuaHang') AND OBJECTPROPERTY(id, N'IsView') = 1)
	DROP VIEW [dbo].[v_KhachHangMuaHang]
Go

/******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:					Description:
**		--------	--------				-----------------------------------
**		04/07/2012	SongTM					Innit created
*******************************************************************************/

create view v_KhachHangMuaHang
as
	select 
		kh.MaKH, kh.TenKH, px.NgayXuatKho, px.SoPX, px.SoHD, ctpx.MaCTPX, sp.MaThuoc, sp.TenBietDuoc, sp.TenHoatChat, 
		dvt.TenDonVi as DonVi, ctpx.SoLuong, ctpx.DonGia, pgh.NgayGiao, pgh.SoPG
	from 
		tbl_KhachHang kh, tbl_PhieuGiaoHang pgh, tbl_PhieuXuat px, tbl_ChiTietPhieuXuat ctpx, 
		tbl_SanPham sp, tbl_ChiTietPhieuNhap ctpn, tbl_DonViTinh dvt, tbl_luuKho lk	
	where 
		kh.MaKH = pgh.MaKH and pgh.SoPX = px.SoPX and px.SoPX = ctpx.SoPX and 
		ctpx.MaLuukho = lk.MaLuuKho and lk.MaThuoc = sp.MaThuoc and sp.MaDonVi = dvt.MaDonVi			
go
